import { Course, DailyDetail, Location, MyApply,  OneOrder, OpenId, OrderDetail, Payment, PayOrder, StudentInfo, KidParent, CourseApply, TeacherInfo, MoreImg} from './request/interface';
import {$axios, request } from './request/request';

export {
  GetClubNews, // 获取活动推送
  GetUserInfo, // 获取用户信息
  AutoGetUserInfo, // 无感认证获取用户信息
  GetOpenId, // 获取OPENID
  SignUp, // 注册
  UpdateUserInfo, // 更新用户信息
  GetCourse, // 获取课程
  GetActDetail, // 获取活动详情
  GetClubDetail, // 获取服务商详情
  GetComments, // 获取活动评价
  StudentApply, // 学生活动报名
  TeacherApply, // 导师活动报名
  GetOrderDetail, // 获取订单详情
  ListMyApply, // 获取我的报名数据
  ListStuApply,//获取学生的报名数据
  Refund, // 退款
  UpdateOneOrder, // 更新订单信息
  DropRecord, // 逻辑删除记录
  CallPayment, // 发起支付请求
  GetPayOrder, // 获取支付订单
  GetDailyDetail, // 学生获取活动行程
  GetKidsDailyDetail, // 获取孩子活动行程
  GetActiveDetail, // 获取正在活动数据
  GetTeacherLocation, // 获取导师位置信息
  UploadLocation, // 上传位置信息
  KidBindParent, // 孩子绑定家长
  SearchParent, // 搜索家长是否存在
  SearchKids, //家长搜索孩子
  ListNews, // 获取新闻
  GetNewsDetail, // 获取新闻详情
  SignOut, // 退出登录
  GetSignUpPermission, // 获取是否开放注册
  FuzzyListSchool, // 模糊搜索学校
  GetKidsList, // 家长获取孩子列表
  VerifyCourseApply, // 活动报名密码验证
  TeacherCancelApply, // 导师取消报名
  GetTeacherActiveDetail, // 导师获取正在活动信息
  GetKidsActiveDetail, /// 家长获取孩子正在活动
  GetMoreImg, // 获取订单的出行人图片补充资料
  UpdateMoreImg, // 更新补充图片资料
  GetStudentList,//获取学生列表
  GetSchoolAndClass,//老师获取自己任教的学校年级班级
  SearchUser, // 搜索家长/孩子是否存在
}
/**
 * @function 获取首页活动推送
 */
const GetClubNews = async (data: {id?: string}) => {
  return $axios({
    url: 'GetClubNews',
    method: 'GET',
    data: data,
  });
}
/**
 * @function 获取用户信息
 */
const GetUserInfo = async (data: {key: string, data: string}) => {
  return $axios({
    url: 'GetUserInfo',
    method: 'GET',
    data: data,
  })
}
/**
 * @function 无感认证获取用户信息
 * @param data 
 */
const AutoGetUserInfo = async (data: {openid: string, id_flag: string}) => {
  return $axios({
    url: 'GetUserInfo2',
    method: 'GET',
    data: data
  })
}

/**
 * @function 获取openid 
 */
const GetOpenId = (data: OpenId) => {
  return new Promise((resolve, reject) => { 
    $axios({
      method: 'GET',
      url: 'getOpenId',
      data: data,
    })
    .then((res) => {
      resolve(res);
    })
    .catch((err) => {
      reject(err);
    })
  })
}
/**
 * @function 保存更改信息
 */
const UpdateUserInfo = async (data: {modelData: any, modelName: string, id: string}) => {
  return request({
    url: 'UpdateUserInfo',
    method: 'GET',
    data: {
      modelName: data.modelName,
      [data.modelName]: data.modelData,
      id: data.id,
    },
  })
}
/**
 * @function 注册
 */
const SignUp = async (data: {key: string, modelName: string, data: string}) => {
  return $axios({
    url: 'Register',
    method: 'GET',
    data: {
      modelName: data.modelName,
      key: data.key,
      data: data.data,
    }
  })
}

/**
 * @function 获取课程信息
 */
const GetCourse = (data: Course) => {
  return $axios({
    url: 'GetCourse',
    method: 'GET',
    data: data,
  })
}

const GetClubDetail = async (param: {clubid: string}) => {
  return $axios({
    method: 'GET',
    url: 'Clubdetail',
    data: param,
  })
}

/**
 * @function 获取某课程的具体信息
 */
const GetActDetail = (param: {id: string, modelName: string}) => {
  return $axios({
    method: 'GET',
    url: 'GetActDetail',
    data: param,
  }) 
}
/**
 * @function 获取课程评论信息
 */
const GetComments = async (param: {courseid: string}) => {
  return $axios({
    url: 'Comment',
    method: 'GET',
    data: param,
  })
}
/**
 * @function 学生课程报名
 */
const StudentApply = async (studentInfo: StudentInfo) => {
  return $axios({
    url: 'Stusign',
    method: 'GET',
    data: studentInfo,
  })
}
/**
 * @function 导师报名
 * @param data 
 */
const TeacherApply = async (data: TeacherInfo) => {
  return $axios({
    url: 'Teasign',
    method: 'GET',
    data: data,
  })
}
/**
 * @function 获取订单详情
 */
const GetOrderDetail = async (orderDetail: OrderDetail) => {
  return $axios({
    url: 'GetOrderDetail',
    method: 'GET',
    data: orderDetail,
  })
}
/**
 * @function 学生获取我的报名，家长获取孩子报名
 */
const ListMyApply = async (param: MyApply) => {
  return $axios({
    url: 'GetMyApply',
    method: 'GET',
    data: param,
  })
}
/**
 * @function 导师获取学生报名
 */
const ListStuApply = async (param: {id: string}) => {
  return $axios({
    url: 'GetStuApply',
    method: 'GET',
    data: param,
  })
}
/**
 * @function 退款
 */
const Refund = async (param: {lowOrderId: string}) => {
  return $axios({
    url: 'tgReverse',
    method: 'GET',
    data: param,
  })
}
/**
 * @function 更新一条订单信息
 */
const UpdateOneOrder = async (data: OneOrder) => {
  return $axios({
    url: 'UpdateOneOrder',
    method: 'GET',
    data: data,
  })
}

/**
 * @function 逻辑删除
 */
const DropRecord = async (data: {id: string, modelName: string}) => {
  return $axios({
    url: 'DropRecord',
    method: 'GET',
    data: data,
  })
}
/**
 * @function 付款
 */
const CallPayment = async (data: Payment) => {
  return $axios({
    method: 'GET',
    url: 'tgPay',
    data: data
  })
}
/**
 * @function 匹配支付订单
 */
const GetPayOrder = async (data: PayOrder) => {
  return $axios({
    url: 'orderFind',
    method: 'GET',
    data: data,
  })
}
/**
 * @function 获取活动行程
 */
const GetDailyDetail = async (data: DailyDetail) => {
  return $axios({
    url: 'DailyDetail',
    method: 'GET',
    data: data,
  })
}
/**
 * @function 家长获取孩子活动行程
 */
const GetKidsDailyDetail = async (data: DailyDetail) => {
  return $axios({
    url: 'GetKidsDailyDetail',
    method: 'GET',
    data: data,
  })
}
/**
 * @function 获取正在活动数据
 * @param data 包含用户id
 * @param type student || teacher || parent
 */
const GetActiveDetail = async (data: {id: string}, type: string = 'student') => {
  const url = type == 'teacher' ? 'TeaNowCourse' : 'ActiveStuDetail';
  return $axios({
    url: url,
    method: 'GET',
    data: data,
  })
}
/**
 * @function 获取导师位置信息
 */
const GetTeacherLocation = async (data: {teaOrderId: string}) => {
  return $axios({
    url: 'GetTeaUpGps',
    method: 'GET',
    data: data
  })
}
/**
 * @function 上传位置信息
 * @param data 上传数据
 */
const UploadLocation = async (data: Location) => {
  return $axios({
    url: 'UpGps',
    method: 'GET',
    data: data
  })
}
/**
 * @function 搜索家长是否存在
 */
const SearchParent = async (data: {name: string, phone: string}) => {
  return $axios({
    url: 'SearchParent',
    method: 'GET',
    data: data
  })
}
/**
 * @function 搜索孩子
 */
const SearchKids = async (data: {name: string, phone: string}) => {
  return $axios({
    url: 'SearchKids',
    method: 'GET',
    data: data
  })
}
/**
 * @function 孩子绑定监护人
 */
const KidBindParent = async (data: KidParent) => {
  return $axios({
    url: 'KidBindParent',
    method: 'GET',
    data: data
  })
}
/**
 * @function 获取新闻
 */
const ListNews = async (data: {type: string}) => {
  return $axios({
    url: 'GetDiff',
    method: 'GET',
    data: data
  })
}
/**
 * @function 获取新闻详情
 */
const GetNewsDetail = async (data: {id: string}) => {
  return $axios({
    url: 'GetDetail',
    method: 'GET',
    data: data
  })
}
/**
 * @function 退出登录
 */
const SignOut = async (data: {id: string, modelName: string}) => {
  return request({
    url: 'SignOut',
    method: 'GET',
    data: data
  })
}
/**
 * @function 获取是否开放注册
 */
const GetSignUpPermission = async () => {
  return $axios({
    url: 'isShow',
    method: 'GET',
    data: {},
  })
}
/**
 * @function 模糊搜索学校列表
 */
const FuzzyListSchool = async (data: {keyword: string}) => {
  return $axios({
    url: 'schoollist',
    method: 'GET',
    data: data,
  })
}

/**
 * @function 家长获取孩子名字
 * @param data: {id} 家长id
 */
const GetKidsList = async (data: {id: string}) => {
  return $axios({
    method: 'GET',
    url: 'GetKidsList',
    data: data,
  })
}
/**
 * @function 活动报名密码验证
 */
const VerifyCourseApply = async (data: CourseApply) => {
  return $axios({
    url: 'CourseCheck',
    method: 'GET',
    data: data
  })
}
/**
 * @function 导师取消报名
 */
const TeacherCancelApply = async (data: {orderid: string}) => {
  return $axios({
    url: 'TeacherCancelApply',
    method: 'GET',
    data: data,
  })
}

/**
 * 2022-9-14
 * @function 老师获取学生列表
 * @param data: {tid} 老师id,{cid}课程id
 */
const GetStudentList = async (data: {tid: string, cid :string}) => {
  return $axios({
    method: 'GET',
    url: 'GetStudentList',
    data: data,
  })
}
/**
 * 2022-9-15
 * @function 老师获取自己任教的学校年级班级
 * @param data: {id} 老师id
 */
const GetSchoolAndClass = async (data: {id: string}) => {
  return $axios({
    method: 'GET',
    url: 'GetSchoolAndClass',
    data: data,
  })
}
/**
 * @function 导师获取正在活动
 */
const GetTeacherActiveDetail = (data: {id: string}) => {
  return $axios({
    url: 'TeaNowCourse',
    method: 'GET',
    data: data,
  })
}
/**
 * @function 家长获取已绑定孩子的正在活动
 */
const GetKidsActiveDetail = async (param: {pid: string}) => {
  return $axios({
    url: 'ParentGetStuActivityDetail',
    method: 'GET',
    data: param,
  })
}
/**
 * @function 获取订单的出行人图片补充资料
 */
const GetMoreImg = async (data: MoreImg) => {
  return $axios({
    url: 'GetMoreImg',
    method: 'GET',
    data: data
  })
}
/**
 * @function 更新补充图片资料
 */
const UpdateMoreImg = async (data: {
    id: string, 
    modelName: 'SignList' | 'TeaSignList', 
    more_file: string}) => {
  return request({
    url: 'UpdateMoreImg',
    method: 'POST',
    data: data,
    header: {
      'Content-Type': 'application/x-www-form-urlencoded',
    }
  })
}
/**
 * @function 搜索家长/孩子是否存在
 */
const SearchUser = async (data: { name: string, phone: string, id_flag: 'parent' | 'student' }) => {
  const {name, phone} = data;
  return $axios({
    url: data.id_flag == 'student' ? 'SearchParent' : 'SearchKids',
    method: 'GET',
    data: {name, phone}
  })
}